//
//  APPTool.swift
//  SpriteKitDemo
//
//  Created by lizhijun on 2023/4/18.
//

import Foundation
import UIKit
struct APPTool{
    static var keyWindow:UIWindow?
   static var isIPhoneRetinaX: Bool {
       if #available(iOS 11, *) {
           guard let bottom = Self.keyWindow?.safeAreaInsets.bottom else { return false }
           return bottom > CGFloat(0)
       }
       return false
   }
   static var topSafeAreaMargin : CGFloat { isIPhoneRetinaX ? 44.0 : 20.0 }

  static  func imageWithColor(_ color: UIColor, size: CGSize) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()!
        context.setFillColor(color.cgColor)
        context.fill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
        return image
    }
}
